package com.efamily.ewallet.client.common.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.efamily.ewallet.client.account.bean.AccountBean;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.data.ModelData;

public class CommentBean extends BaseTreeModel {
	public static CommentBean createCommentBean(AccountBean author, AccountBean owner, String content){
		CommentBean commentBean = new CommentBean();
		commentBean.setAuthor(author);
		commentBean.setOwner(owner);
		commentBean.setComment(content);
		return commentBean;
	}
	public int getId() {
		return get("id", -1);
	}

	public void setId(int id) {
		set("id", id);
	}

	public String getComment() {
		return get("comment", "");
	}

	public void setComment(String content) {
		set("comment", content);
	}

	public Date getDate() {
		return get("date");
	}

	public void setDate(Date date) {
		set("date", date);
	}

	public AccountBean getAuthor() {
		return get("author");
	}

	public void setAuthor(AccountBean author) {
		set("author", author);
	}
	public AccountBean getOwner() {
		return get("owner");
	}

	public void setOwner(AccountBean owner) {
		set("owner", owner);
	}

	public List<CommentBean> getReplies() {
		List<CommentBean> result = new ArrayList<CommentBean>();
		for(ModelData child : children){
			result.add((CommentBean)child);
		}
		return result;
	}

	public void setReplies(List<CommentBean> replies) {
		for (CommentBean reply : replies) {
			addReply(reply);
		}
	}

	public void addReply(CommentBean reply) {
		add(reply);
	}

	public void removeReply(CommentBean reply) {
		remove(reply);
	}

}
